package com.ebt.m.customer.view;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.ebt.m.R;
import com.ebt.m.customer.entity.PolicyBean;

import java.util.List;

/**
 * Created by archer.qi on 2016/12/13.
 */
public class PopupWindowBuilder {

    private Context context;

    private View contentView;
    private ListView listView;

    private int width;
    private int height;

    /* 保单数据*/
    private PolicyBean policy;

    public PopupWindowBuilder(Context context) {
        this.context = context;
        contentView = LayoutInflater.from(context).inflate(R.layout.window_list, null);
        listView = (ListView) contentView.findViewById(R.id.window_listview);
    }

    public PopupWindowBuilder fill(List<String> strs) {
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, strs);
        listView.setAdapter(adapter);
        return this;
    }

    public PopupWindowBuilder width(int w) {
        if (w <= 0) {
            width = WindowManager.LayoutParams.WRAP_CONTENT;
        } else {
            width = w;
        }
        return this;
    }

    public PopupWindowBuilder height(int h) {
        if (h <= 0) {
            height = WindowManager.LayoutParams.WRAP_CONTENT;
        } else {
            height = h;
        }
        return this;
    }

    public PopupWindowBuilder listen(AdapterView.OnItemClickListener listener) {
        listView.setOnItemClickListener(listener);
        return this;
    }

    public PopupWindow create() {
        PopupWindow window = new PopupWindow(contentView, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
        window.setTouchable(true);
        window.setOutsideTouchable(true);
        window.setBackgroundDrawable(new BitmapDrawable());
        return window;
    }

}
